<?php
/*
 * Created on 2017-8-8
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
 
 // 线下转账支付接口.
function pay_transform_account($json , $session)
{
	$ret = array() ;
	$ret['data'] = array() ;
	
	$uid = util_set_GETUID_for_SESSION($session) ;
	if ($uid <= 0)
	{
		$ret['status'] = $GLOBALS["ERR"]["ERR_USER_NOTFIND"] ;
		$ret['message'] = $GLOBALS["MES"]["ERR_USER_NOTFIND"] ;
		return $ret ;
	}
	
	$out_trade_no = get_jsonValue($json,"order_id") ;				// 我们自己的订单编号
	$order_price  = doubleval(get_jsonValue($json,"order_price")) ;	// 当前支付的金额
	$pay_count	  = intval(get_jsonValue($json,"pay_count")) ;		// 当前第几次支付（多次支付1开始累加）
	if ($pay_count <= 0)		$pay_count = 1 ;
	
	$ret = pay_trade_state_check($out_trade_no , $uid , $order_price , $pay_count) ;
	if ($ret['status'] != 0){
		return $ret ;
	}
	$one_trade = $ret['trade'] ;
	unset($ret['trade']); 
	
	$account = get_jsonValue($json,"account") ;				// 银行账号
	$accountname = get_jsonValue($json,"accountName") ;		// 户名
	$image = get_jsonValue($json,"image") ;					// 图片数据经过 base64 编码 转账凭证
	$data = base64_decode($image) ;
	if ($data == FALSE){
		$ret['status'] = $GLOBALS["ERR"]["ERR_BASE64"] ;
		$ret['message'] = $GLOBALS["MES"]["ERR_BASE64"] ;
		return $ret ;
	}
	$newid = image_data_save2($data , $ret) ;
	if ($newid == 0){
		return $ret ;
	}
		
	
	$update_tf_trade_no = $out_trade_no."_".$pay_count."_".date("s",time()) ;
	$prepay_id = "trans_$update_tf_trade_no" ; 
	
	$xmlarr = array() ;
	$xmlarr['imageid'] = $newid ;
	$xmlarr['account'] = $account ;
	$xmlarr['accountName'] = $accountname ;
	
	$memo_xml = json_encode($xmlarr,JSON_UNESCAPED_UNICODE); ;		// 转账凭证图片id,账号,户名等
	
	if (create_pay_beforehand_order($uid , $prepay_id , 5 , $out_trade_no , $pay_count , $memo_xml , $order_price) == false){
		$ret['status'] = $GLOBALS["ERR"]["ERR_DATABASE"] ;
		$ret['message'] = $GLOBALS["MES"]["ERR_DATABASE"] ;
		return $ret ;			
	}
	sql_query("update `pay_trade` set `trade_state` = 9 where `trade_no` = '$out_trade_no'") ;	// 转账审核中
	
	return $ret ;
	
}
 
 
?>
